<template>
  <div class="purchaseForm">
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px">
      <el-form :inline="true">
        <el-form-item>
          <el-button type="primary" @click="clickAdd">新增</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="withdrawList(e)">撤回</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="24" class="toolbar">
      <div class="apply-data">
        <div class="ad-item">
          <div class="tit">部门:</div>
          <div class="text">{{ dataDetail.deptname }}</div>
        </div>
        <div class="ad-item">
          <div class="tit">日期:</div>
          <div class="text">{{ formatTime(dataDetail.createtime) }}</div>
        </div>
      </div>
    </el-col>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column prop="productName" label="产品名称"></el-table-column>
      <el-table-column prop="file" label="附件"></el-table-column>
      <el-table-column prop="invspec" label="规格型号"></el-table-column>
      <el-table-column prop label="供应商"></el-table-column>
      <el-table-column prop="unitweight" label="质量标准"></el-table-column>
      <!-- <el-table-column prop="qualityStandard" label="单位"></el-table-column> -->
      <el-table-column label="历史" align="center">
        <el-table-column prop="historical" label="采购量"></el-table-column>
        <el-table-column
          prop="histMaxMoney"
          label="最高价"
        ></el-table-column>
        <el-table-column
          prop="histMinMoney"
          label="最低价"
        ></el-table-column>
        <el-table-column
          prop="histAvgMoney"
          label="平均价"
        ></el-table-column>
        <el-table-column
          prop="contractPrice"
          label="合同价"
        ></el-table-column>
        <el-table-column label="是否含运费">
          <template slot-scope="scope">
            <div>{{ scope.row.isFreight == "N" ? "否" : "是" }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="payType"
          label="付款方式"
        ></el-table-column>
        <el-table-column prop="lastBuyer" label="上期采购员"></el-table-column>
        <el-table-column prop label="历史评价"></el-table-column>
      </el-table-column>
      <el-table-column
        prop="requisitionsNowHave"
        label="现有库存量"
      ></el-table-column>
      <el-table-column prop label="库存保质期"></el-table-column>
      <el-table-column width="120" label="选择询价单" align="center">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="handleData(scope)"
            >选择询价单</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="请购单数据"
        align="center"
        :label-class-name="'labelFont'"
      >
        <el-table-column prop="file" label="附件" width="140" align="center">
          <template slot-scope="scope">
            <div>
              <el-button
                @click="showImg(scope.row.productUrl)"
                size="small"
                type="primary"
                >查看</el-button
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="询价单供应商"
          prop="supplierName"
        ></el-table-column>
        <el-table-column
          label="单价(元)"
          align="center"
          prop="requisitionsUnitPrice"
        ></el-table-column>
        <el-table-column prop="qualityStandard" label="单位"></el-table-column>
        <el-table-column
          label="本期申请数量"
          align="center"
          prop="requisitionsHowMany"
        ></el-table-column>
        <el-table-column
          label="税率(元)"
          align="center"
          prop="requisitionsTaxRate"
        ></el-table-column>
        <el-table-column
          label="总价"
          align="center"
          prop="inquiryAllMoneys"
        ></el-table-column>
        <el-table-column label="是否含运费" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.requisitionsIsFreight == "Y" ? "是" : "否" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="付款方式"
          align="center"
          prop="requisitionsPayType"
        ></el-table-column>
        <el-table-column
          label="地址及联系方式"
          align="center"
          prop="requisitionsAddressPhone"
        ></el-table-column>
        <el-table-column
          label="用途"
          align="center"
          prop="requisitionsHowUse"
        ></el-table-column>
        <el-table-column
          label="备注"
          align="center"
          prop="requisitionsRemark"
        ></el-table-column>
      </el-table-column>
    </el-table>
    <div class="inquire-table" v-if="inquireTable.length > 0">
      <div class="it-tit">商品询价汇总数据：</div>
      <el-table :data="inquireTable">
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column prop="productName" label="产品名称"></el-table-column>
        <el-table-column prop="file" label="附件"></el-table-column>
        <el-table-column prop="invspec" label="规格型号"></el-table-column>
        <el-table-column prop label="供应商"></el-table-column>
        <el-table-column prop="unitweight" label="质量标准"></el-table-column>
        <!-- <el-table-column prop="qualityStandard" label="单位"></el-table-column> -->
        <el-table-column prop="historical" label="历史采购量"></el-table-column>
        <el-table-column
          prop="histMaxMoney"
          label="最高价(历史)"
        ></el-table-column>
        <el-table-column
          prop="histMinMoney"
          label="最低价(历史)"
        ></el-table-column>
        <el-table-column
          prop="histAvgMoney"
          label="平均价(历史)"
        ></el-table-column>
        <el-table-column
          prop="contractPrice"
          label="合同价(历史)"
        ></el-table-column>
        <el-table-column label="是否含运费(历史)">
          <template slot-scope="scope">
            <div>{{ scope.row.isFreight == "N" ? "否" : "是" }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="payType"
          label="付款方式(历史)"
        ></el-table-column>
        <el-table-column prop="lastBuyer" label="上期采购员"></el-table-column>
        <el-table-column prop label="历史评价"></el-table-column>
        <el-table-column
          prop="requisitionsNowHave"
          label="现有库存量"
        ></el-table-column>
        <!-- <el-table-column prop label="库存保质期"></el-table-column> -->
        <el-table-column
          label="请购单数据"
          align="center"
          :label-class-name="'labelFont'"
        >
          <el-table-column prop="file" label="附件" width="140" align="center">
            <template slot-scope="scope">
              <div>
                <el-button
                  @click="showImg(scope.row.productUrl)"
                  size="small"
                  type="primary"
                  >查看</el-button
                >
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="询价单供应商"
            prop="supplierName"
          ></el-table-column>

          <el-table-column
            label="单价(元)"
            align="center"
            prop="requisitionsUnitPrice"
          ></el-table-column>
          <el-table-column
            prop="qualityStandard"
            label="单位"
          ></el-table-column>
          <el-table-column
            label="本期申请数量"
            align="center"
            prop="requisitionsHowMany"
          ></el-table-column>
          <el-table-column
            label="税率(元)"
            align="center"
            prop="requisitionsTaxRate"
          ></el-table-column>
          <el-table-column
            label="总价"
            align="center"
            prop="inquiryAllMoneys"
          ></el-table-column>
          <el-table-column label="是否含运费" align="center">
            <template slot-scope="scope">
              <div>
                {{ scope.row.requisitionsIsFreight == "Y" ? "是" : "否" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="付款方式"
            align="center"
            prop="requisitionsPayType"
          ></el-table-column>
          <el-table-column
            label="地址及联系方式"
            align="center"
            prop="requisitionsAddressPhone"
          ></el-table-column>
          <el-table-column
            label="用途"
            align="center"
            prop="requisitionsHowUse"
          ></el-table-column>
          <el-table-column
            label="备注"
            align="center"
            prop="requisitionsRemark"
          ></el-table-column>
        </el-table-column>
        <el-table-column
          label="最终确认单数据"
          align="center"
          :label-class-name="'labelFont'"
        >
          <el-table-column label="单价" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryUnitPrice }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="qualityStandard"
            label="单位"
          ></el-table-column>
          <el-table-column label="税率" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryTaxRate }}</div>
            </template>
          </el-table-column>
          <el-table-column label="总价" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryAllMoneys }}</div>
            </template>
          </el-table-column>

          <el-table-column label="付款方式" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryPayType }}</div>
            </template>
          </el-table-column>

          <el-table-column label="是否含运费" align="center">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.wlcSysInquiryLast.inquiryIsFreight == "Y"
                    ? "是"
                    : "否"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="供应商名称" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryCustname }}</div>
            </template>
          </el-table-column>
          <el-table-column label="地址及联系方式" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryAddressPhone }}</div>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysInquiryLast.inquiryRemark }}</div>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <el-col :span="24" class="toolbar" v-if="inquireTable.length > 0">
      <div class="total-data">
        <div class="total-item">合计</div>
        <div class="total-item">数量:{{ totalData.num }}</div>
        <div class="total-item">总价（元）:{{ totalData.price }}</div>
      </div>
    </el-col>
    <el-col :span="24" class="toolbar">
      <div class="sign-remarks">
        <div class="tit">备注:{{ dataDetail.remark }}</div>
      </div>
    </el-col>
    <el-col :span="24" class="toolbar">
      <div class="sign-data">
        <div class="sd-item">制单人:{{ dataDetail.singlePerson }}</div>
        <div class="sd-item">审核人:{{ dataDetail.auditor }}</div>
        <div class="sd-item">
          审核时间:{{ formatTime(dataDetail.auditTime) }}
        </div>
        <div class="sd-item">变更人:{{ dataDetail.modifiername }}</div>
        <div class="sd-item">
          变更日期:{{ formatTime(dataDetail.modifytime) }}
        </div>
      </div>
    </el-col>

    <!-- 选择请购单弹窗 -->
    <el-dialog
      title="请购单列表"
      :visible.sync="dialogTableVisible"
      width="60%"
      top="7vh"
    >
      <el-table :data="productList" height="50vh" ref="multipleTable">
        <el-table-column
          property="unitname"
          label="公司"
          align="center"
        ></el-table-column>
        <el-table-column
          property="custname"
          label="建议供应商"
          align="center"
        ></el-table-column>
        <el-table-column
          property="psnname"
          label="请购人"
          align="center"
        ></el-table-column>
        <el-table-column label="选择" align="center">
          <template slot-scope="scope">
            <el-button
              size="small"
              type="primary"
              @click="handleSelectionChange(scope.row)"
              >选择</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 选择询价单弹窗 -->
    <el-dialog
      title="询价单列表"
      :visible.sync="dialogInquire"
      width="80%"
      top="7vh"
    >
      <el-table
        :data="InquiryList"
        height="50vh"
        @selection-change="handleInquiryList"
        ref="multipleTable"
      >
        <el-table-column label="商品名称" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.productName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="附件" align="center">
          <template slot-scope="scope">
            <div class="inquiry-list">
              <!-- <img src="../../assets/logo.png" alt=""> -->
              <img :src="scope.row.inquiryProductUrl" alt />
              <!-- <el-button @click="showImg(scope.row.inquiryProductUrl)" size="small" type="primary">查看</el-button> -->
            </div>
          </template>
        </el-table-column>
        <el-table-column label="规格型号" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.invspec }}</div>
          </template>
        </el-table-column>
        <el-table-column
          property="inquiryCustname"
          label="供应商"
          align="center"
        ></el-table-column>
        <el-table-column label="质量标准" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.qualityStandard }}</div>
          </template>
        </el-table-column>
        <el-table-column
          property="inquiryUnitPrice"
          label="单价"
          align="center"
        ></el-table-column>
        <el-table-column label="单位" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.measurement }}</div>
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.requisitionsHowMany }}</div>
          </template>
        </el-table-column>
        <el-table-column label="税率" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.requisitionsTaxRate }}</div>
          </template>
        </el-table-column>
        <el-table-column
          property="inquiryAllMoneys"
          label="总价"
          align="center"
        ></el-table-column>
        <el-table-column align="center" label="历史">
          <el-table-column align="center" label="采购量">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.historical }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="最高价">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.histMaxMoney }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="最低价">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.histMinMoney }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="平均价">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.histAvgMoney }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="合同价">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.contractPrice }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="是否含运费">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.wlcSysBack.requisitionsIsFreight == "Y"
                    ? "是"
                    : "否"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="付款方式">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsPayType }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="上期采购员">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.lastBuyer }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="历史评价"></el-table-column>
        </el-table-column>
        <el-table-column align="center" label="现有库存">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.requisitionsNowHave }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="现有库存">
          <template slot-scope="scope">
            <div>{{ scope.row.wlcSysBack.requisitionsNowHave }}</div>
          </template>
        </el-table-column>
        <el-table-column label="是否含运费" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.inquiryIsFreight == "Y" ? "是" : "否" }}</div>
          </template>
        </el-table-column>
        <el-table-column
          property="inquiryPayType"
          label="付款方式"
          align="center"
        ></el-table-column>
        <el-table-column
          property="inquiryAddressPhone"
          label="地址及联系方式"
          align="center"
        ></el-table-column>
        <el-table-column
          property="inquiryRemark"
          label="备注"
          align="center"
        ></el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            <!-- <i class="el-icon-circle-check" v-if="scope.row.checked == 1"></i> -->
            <el-checkbox
              v-model="scope.row.isChecked"
              @change="selectInquiryLine(scope)"
            ></el-checkbox>
            <!-- <el-checkbox v-model="scope.row.isChecked"></el-checkbox> -->
          </template>
        </el-table-column>
        <!-- 请购单数据 -->
        <el-table-column
          label="请购单数据"
          align="center"
          :label-class-name="'labelFont'"
        >
          <el-table-column prop="file" label="附件" width="140" align="center">
            <template slot-scope="scope">
              <div>
                <el-button
                  @click="showImg(scope.row.wlcSysBack.productUrl)"
                  size="small"
                  type="primary"
                  >查看</el-button
                >
              </div>
            </template>
          </el-table-column>
          <el-table-column label="供应商" prop="supplierName">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.supplierName }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="单价(元)"
            align="center"
            prop="requisitionsUnitPrice"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsUnitPrice }}</div>
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.measurement }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="税率(元)"
            align="center"
            prop="requisitionsTaxRate"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsTaxRate }}</div>
            </template>
          </el-table-column>
          <el-table-column label="总价" align="center" prop="inquiryAllMoneys">
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.inquiryAllMoneys }}</div>
            </template>
          </el-table-column>
          <el-table-column label="是否含运费" align="center">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.wlcSysBack.requisitionsIsFreight == "Y"
                    ? "是"
                    : "否"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="付款方式"
            align="center"
            prop="requisitionsPayType"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsPayType }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="地址及联系方式"
            align="center"
            prop="requisitionsAddressPhone"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsAddressPhone }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="用途"
            align="center"
            prop="requisitionsHowUse"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsHowUse }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="本期申请数量"
            align="center"
            prop="requisitionsHowMany"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsHowMany }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="备注"
            align="center"
            prop="requisitionsRemark"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.wlcSysBack.requisitionsRemark }}</div>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="finishSelect(scope.row,scope)">保存</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogInquire = false">取 消</el-button>
        <el-button type="primary" @click="clickInquire()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 展示图片 -->
    <el-dialog title="附件" :visible.sync="dialogImgShow">
      <div class="showImgDiv">
        <img :src="showImgUrl" alt />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  wlcSysInquiryList,
  wlcSysInquiryDetail,
  wlcSysInquiryWithBackIdSelectInquiry,
  wlcSysInquirySaveWlcSysInquiryLast,
  wlcSysInquiryAdd,
  wlcSysInquirySubmit,
  checkedWlcSysInquiryLastDetail,
  wlcSysInquiryWithdrawTicket,
} from "../../api/api";
import moment from "moment";
export default {
  data() {
    return {
      tableData: [],
      page: {
        page: 1,
        pageSize: 10,
      },
      showImgUrl: "",
      dialogImgShow: false, //是否展示图片
      productList: [], //新增 询价单列表
      dialogTableVisible: false, //询价单列表  弹窗
      dataDetail: {}, //请购单详情

      // 部门申请的数据列表
      deparArr: [],
      //新增完后选择的请购单
      InquiryList: [],
      dialogInquire: false, //请购单列表弹窗
      tableIndex: null, //点击第几个table
      selectInquiryArr: [], //选中的请购单
      inquiryData: {},
      inquireTable: [], //单个商品询价汇总数据
      totalData: {
        num: 0,
        price: 0,
      },
      tableAllID: "", //点击选择询价单  allId
    };
  },
  methods: {
    //选择完询价单  点击确定
    clickInquire() {
      let isSelect = false;
      let obj = {};
      this.InquiryList.map((item) => {
        if (item.checked == 1) {
          isSelect = true;
          obj = item;
        }
      });
      if (isSelect) {
        this.finishSelect(obj);
      } else {
        this.$message({
          message: "请选择询价单",
          type: "warning",
        });
      }
    },
    //撤回
    withdrawList() {
      this.$confirm("是否撤回?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        wlcSysInquiryWithdrawTicket([{ id: this.$route.query.id }]).then(
          (res) => {
            // console.log(res);
            this.$message({
              type: "success",
              message: "撤回成功!",
            });
          }
        );
      });
    },

    //选择询价单
    selectInquiryLine(e) {
      this.InquiryList = this.InquiryList.map((item, index) => {
        if (index == e.$index) {
          item.checked = "1";
          item.isChecked = true;
        } else {
          item.checked = "0";
          item.isChecked = false;
        }
        return item;
      });
    },
    //展示图片
    showImg(url) {
      if (url) {
        this.showImgUrl = url;
        this.dialogImgShow = true;
      } else {
        this.$message({
          message: "暂无图片",
          type: "warning",
        });
      }
    },
    //点击提交
    submitForm() {
      if (!this.inquiryData.id) {
        this.$message({
          message: "请先选中询价单",
          type: "warning",
        });
        return;
      }
      for (let i = 0; i < this.tableData.length; i++) {
        let list = this.tableData[i].wlcSysBack || [];
        let isSelect = false;
        list.map((item) => {
          console.log(item);
          if (item.checked == 1) {
            isSelect = true;
          }
        });
        console.log(isSelect);
        if (!isSelect) {
          this.$message({
            message: "还有商品未选择询价单",
            type: "warning",
          });
          return;
        }
      }
      wlcSysInquirySubmit({ backId: this.inquiryData.backId, type: 2 }).then(
        (res) => {
          this.dialogInquire = false;
          this.$message({
            message: "提交审核成功",
            type: "success",
          });
        }
      );
    },
    //格式化时间
    formatTime(time) {
      if (time) {
        return moment(time).format("YYYY-MM-DD");
      } else {
        return "";
      }
    },
    //点击选择询价单
    chooseInquiry() {
      this.dialogInquire = true;
    },
    //获取询价列表
    getInquiryList() {
      wlcSysInquiryList({ page: this.page }).then((res) => {
        this.total = res.total;
        this.productList = res.records;
      });
    },
    //点击新增
    clickAdd() {
      this.dialogTableVisible = true;
    },
    //选中新增弹窗列表
    handleSelectionChange(data) {
      this.deparArr = [];
      this.getDetail(data.id);
      this.dialogTableVisible = false;
    },
    //获取请购单详情
    getDetail(id, buyType) {
      wlcSysInquiryDetail({ allId: id }).then((res) => {
        this.dataDetail = res;
        var list = res.wlcSysBack;
        for (var i = 0; i < list.length; i++) {
          for (let b = 0; b < list[i].wlcSysBack.length; b++) {
            let obj = list[i].wlcSysBack[b];
            if (obj.checked == 1) {
              this.getInquiryDetail(obj.backId, i + 1);
            }
          }
        }
        this.tableData = list;
      });
    },
    //选择请购单
    handleInquiryList(val) {
      this.selectInquiryArr = val;
    },

    //table点击选择询价单
    handleData(e) {
      console.log(e);
      this.tableIndex = e.$index;
      this.tableAllID = e.row.allId;
      wlcSysInquiryWithBackIdSelectInquiry({ id: e.row.id }).then((res) => {
        // this.InquiryList = res;
        this.InquiryList = res.map((item) => {
          if (item.checked == 1) {
            item.isChecked = true;
          } else {
            item.isChecked = false;
          }
          return item;
        });
        this.dialogInquire = true;
      });
    },
    //询价单点击保存
    finishSelect(e, data) {
      console.log(e, data);
      wlcSysInquirySaveWlcSysInquiryLast(e).then((res) => {
        this.inquiryData = e;
        this.dialogInquire = false;
        this.tableData[this.tableIndex].hasSave = true;
        this.$message({
          message: "保存成功,确认无误后可点击提交",
          type: "success",
        });
        this.getDetail(this.tableAllID);
        // this.getInquiryDetail(e.backId, this.tableIndex + 1);
      });
    },
    //单个商品询价汇总数据
    getInquiryDetail(backId, index) {
      checkedWlcSysInquiryLastDetail({ backId }).then((res) => {
        let isRepeat = false;
        // let objData = res.wlcSysInquiryLast;
        for (let i = 0; i < this.inquireTable.length; i++) {
          if (this.inquireTable[i].index == index) {
            isRepeat = true;
            this.inquireTable[i] = res;
            this.inquireTable[i].index = index;
          }
        }
        if (!isRepeat) {
          res.index = index;
          this.inquireTable.push(res);
        }
        // this.inquireTable[i].requisitionsHowMany = res.requisitionsHowMany;
        this.inquireTable.sort((a, b) => {
          return b.index - a.index;
        });

        let total = 0;
        let price = 0;
        this.inquireTable.map((item, index) => {
          total = total + item.requisitionsHowMany * 1;
          price = price + item.wlcSysInquiryLast.inquiryAllMoneys * 1;
        });
        this.totalData = {
          num: total,
          price,
        };
      });
    },
  },
  created() {
    if (this.$route.query.id) {
      this.getDetail(this.$route.query.id);
    }
    this.getInquiryList();
  },
};
</script>

<style lang="less" scoped>
.total-data {
  display: flex;
  justify-content: center;
  .total-item {
    font-weight: bold;
    font-size: 16px;
    color: #666;
    width: 20%;
  }
}
.apply-data {
  display: flex;
  flex-wrap: wrap;
  .ad-item {
    display: flex;
    height: 30px;
    line-height: 30px;
    margin-right: 70px;
    color: #666;
    font-size: 14px;
  }
}
.sign-remarks {
  width: 100%;
  border-bottom: 1px solid #999;
  font-size: 14px;
  height: 40px;
  line-height: 40px;
  color: #333;
}
.sign-data {
  display: flex;
  .sd-item {
    flex: 1;
    color: #333;
  }
}
.inquiryTit {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 10px;
}
.inquiry-list {
  img {
    max-width: 75px;
    max-height: 75px;
  }
}
.el-icon-circle-check {
  font-size: 20px;
  color: #409eff;
}
.inquire-table {
  margin-top: 20px;
  .it-tit {
    color: #666;
    font-weight: bold;
    margin-bottom: 10px;
  }
}
.showImgDiv {
  width: 100%;
  img {
    width: 100%;
  }
}
</style>
<style lang="less">
.el-table th > .cell.labelFont {
  font-weight: bold;
  color: #333 !important;
}
</style>
